import React, { Component } from 'react'
import { Alert, message } from "antd"
import QueryList from '@/components/basicWidget/QueryList'
import { post } from '@/utils/requestUtil'

/**
 * 博客回收站
 * @author liu_jshan
 * @version 1.0 20240414
 */
class BlogRecyclingSite extends Component {

    constructor(props) {
        super(props)
        this.state = {
        }
    }

    async componentDidMount() {

    }

    onRecover = async () => {
        const selectedRowKeys = this.queryList.state.selectedRowKeys
        if (selectedRowKeys.length === 0) {
            message.warning('请选择要恢复的数据')
            return false
        }
        const response = await post('/blog/reclaim/recover', {
            body: JSON.stringify(selectedRowKeys)
        })
        if (response && response.code === 200) {
            message.success('恢复成功')
            await this.queryList.onQuery()
        } else {
            message.warning('恢复失败，请联系管理员')
        }
    }

    onRemove = async () => {
        const selectedRowKeys = this.queryList.state.selectedRowKeys
        if (selectedRowKeys.length === 0) {
            message.warning('请选择要清除的数据')
            return false
        }
        const response = await post('/blog/reclaim/remove', {
            body: JSON.stringify(selectedRowKeys)
        })
        if (response && response.code === 200) {
            message.success('清除成功')
            await this.queryList.onQuery()
        } else {
            message.warning('清除失败，请联系管理员')
        }
    }

    render() {
        return (
            <>
                <Alert
                    style={{margin: '0 5px'}}
                    description="注意！回收站中的数据会保存30天，超过30天的数据将自动清除且无法恢复！"
                    type="info"
                    showIcon
                />
                <QueryList
                    queryCode='blogRecyclingSite'
                    refData={{
                        custId: this.props.user.id
                    }}
                    onRecover={this.onRecover}
                    onRemove={this.onRemove}
                    ref={queryList => this.queryList = queryList}
                >
                </QueryList>
            </>
        )
    }
}

export default BlogRecyclingSite
